/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.toedter.calendar;

import java.awt.Color;
import java.util.ArrayList;
import java.util.Calendar;

/**
 *
 * @author prophet
 */
public class DefaultHolidayPolicy implements HolidayPolicy{

    private ArrayList<Calendar> holidays;
    private ArrayList<Calendar> weekdays;

    public DefaultHolidayPolicy(){
        holidays=new ArrayList<Calendar>();
        weekdays=new ArrayList<Calendar>();
    }

    public boolean addHoliday(Calendar date){
        for(Calendar tmpCalendar:holidays){
            if(tmpCalendar.get(Calendar.DAY_OF_YEAR)==date.get(Calendar.DAY_OF_YEAR)&&
                    tmpCalendar.get(Calendar.YEAR)==date.get(Calendar.YEAR)){
                return false;
            }
        }
        holidays.add(date);        
        return true;
    }
    
    public boolean removeHoliday(Calendar date){
        for(Calendar tmpCalendar:holidays){
            if(tmpCalendar.get(Calendar.DAY_OF_YEAR)==date.get(Calendar.DAY_OF_YEAR)&&
                    tmpCalendar.get(Calendar.YEAR)==date.get(Calendar.YEAR)){
                holidays.remove(date);
                return true;
            }
        }
        return false;
    }

    public boolean removeWeekday(Calendar date){
        for(Calendar tmpCalendar:weekdays){
            if(tmpCalendar.get(Calendar.DAY_OF_YEAR)==date.get(Calendar.DAY_OF_YEAR)&&
                    tmpCalendar.get(Calendar.YEAR)==date.get(Calendar.YEAR)){
                weekdays.remove(date);
                return true;
            }
        }
        return false;
    }
    
    public boolean addWeekday(Calendar date){
        for(Calendar tmpCalendar:weekdays){
            if(tmpCalendar.get(Calendar.DAY_OF_YEAR)==date.get(Calendar.DAY_OF_YEAR)&&
                    tmpCalendar.get(Calendar.YEAR)==date.get(Calendar.YEAR)){
                return false;
            }
        }
        weekdays.add(date);
        return true;
    }
    
    public void clearHolidays(){
        holidays.clear();
    }
    
    public void clearWeekdays(){
        weekdays.clear();
    }

    public String getHollidayName(Calendar date) {
        return null;
    }

    public boolean isHoliday(Calendar date) {
        for(Calendar tmpCalendar:weekdays){
            if(tmpCalendar.get(Calendar.DAY_OF_YEAR)==date.get(Calendar.DAY_OF_YEAR)&&
                    tmpCalendar.get(Calendar.YEAR)==date.get(Calendar.YEAR)){
                return false;
            }
        }
        for(Calendar tmpCalendar:holidays){
            if(tmpCalendar.get(Calendar.DAY_OF_YEAR)==date.get(Calendar.DAY_OF_YEAR)&&
                    tmpCalendar.get(Calendar.YEAR)==date.get(Calendar.YEAR)){
                return true;
            }
        }
        return isWeekend(date);
    }

    public boolean isWeekend(Calendar date) {
        if(date.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY||
                date.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
            return true;
        }
        return false;
    }

}
